<template>
	<div>
		<el-dialog :title="title" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible">
			<el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading"
				:class="method==='view'?'readonly':''" :disabled="method==='view'" label-width="120px">
				<el-row :gutter="15">
					<el-col :span="12">
						<el-form-item label="归属用户" prop="sysuser.id" :rules="[
                  {required: true, message:'归属用户不能为空', trigger:'blur'}
                 ]">
							<user-select :limit='1' :value="inputForm.sysuser.id"
								@getValue='(value) => {inputForm.sysuser.id=value}'></user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="是否报销" prop="isaccount" :rules="[
                  {required: true, message:'是否报销不能为空', trigger:'blur'}
                 ]">
							<el-select v-model="inputForm.isaccount" placeholder="请选择" style="width: 100%;">
								<el-option v-for="item in $dictUtils.getDictList('is_account')" :key="item.value"
									:label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="12">
						<el-form-item label="发票id" prop="imageID" :rules="[
                  {required: true, message:'发票id不能为空', trigger:'blur'}
                 ]">
							<el-input v-model="inputForm.imageID" placeholder="请填写发票id"></el-input>
						</el-form-item>
					</el-col> -->
					<!-- <el-col :span="12">
						<el-form-item label="发票原件" prop="oldUrl" :rules="[
                  {required: true, message:'发票原件不能为空', trigger:'blur'}
                 ]">
							<el-input v-model="inputForm.oldUrl" placeholder="请填写发票原件"></el-input>
						</el-form-item>
					</el-col> -->
					<!-- <el-col :span="12">
						<el-form-item label="发票图片url" prop="dmzUrl" :rules="[
                  {required: true, message:'发票图片url不能为空', trigger:'blur'}
                 ]">
							<el-input v-model="inputForm.dmzUrl" placeholder="请填写发票图片url"></el-input>
						</el-form-item>
					</el-col> -->
					<el-col :span="12">
						<el-form-item label="发票类型" prop="type" :rules="[
                  {required: true, message:'发票类型不能为空', trigger:'blur'}
                 ]">
							<el-select v-model="inputForm.type" placeholder="请选择" style="width: 100%;">
								<el-option v-for="item in $dictUtils.getDictList('invoicebill_type')" :key="item.value"
									:label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="发票代码" prop="invoiceCode" :rules="[
                 ]">
							<el-input v-model="inputForm.invoiceCode" placeholder="请填写发票代码"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="发票号码" prop="invoiceNo" :rules="[
                 ]">
							<el-input v-model="inputForm.invoiceNo" placeholder="请填写发票号码"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="开票日期" prop="invoiceDate" :rules="[
                 ]">
							<el-input v-model="inputForm.invoiceDate" placeholder="请填写开票日期"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="不含税价格" prop="noTaxAmount" :rules="[
                 ]">
							<el-input v-model="inputForm.noTaxAmount" placeholder="请填写不含税价格"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="校验码" prop="checkCode" :rules="[
                 ]">
							<el-input v-model="inputForm.checkCode" placeholder="请填写校验码"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="含税价格" prop="withTaxAmount" :rules="[
                 ]">
							<el-input v-model="inputForm.withTaxAmount" placeholder="请填写含税价格"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="总价格" prop="amount" :rules="[
                 ]">
							<el-input v-model="inputForm.amount" placeholder="请填写总价格"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="购方税号" prop="payerTaxNo" :rules="[
                 ]">
							<el-input v-model="inputForm.payerTaxNo" placeholder="请填写购方税号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="购方姓名" prop="payerName" :rules="[
                 ]">
							<el-input v-model="inputForm.payerName" placeholder="请填写购方姓名"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="销方税号" prop="sellerTaxNo" :rules="[
                 ]">
							<el-input v-model="inputForm.sellerTaxNo" placeholder="请填写销方税号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="销方姓名" prop="sellerName" :rules="[
                 ]">
							<el-input v-model="inputForm.sellerName" placeholder="请填写销方姓名"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="购买方地址 电话" prop="buyerAddTel" :rules="[
                 ]">
							<el-input v-model="inputForm.buyerAddTel" placeholder="请填写购买方地址、电话"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="购买方开户行及账号" prop="buyerBankNo" :rules="[
                 ]">
							<el-input v-model="inputForm.buyerBankNo" placeholder="请填写购买方开户行及账号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="销方地址电话" prop="sellerAddTel" :rules="[
                 ]">
							<el-input v-model="inputForm.sellerAddTel" placeholder="请填写销方地址电话"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="销方开户行及账号" prop="sellerBankNo" :rules="[
                 ]">
							<el-input v-model="inputForm.sellerBankNo" placeholder="请填写销方开户行及账号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="备注信息" prop="remarks" :rules="[
                 ]">
							<el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button size="small" @click="visible = false">关闭</el-button>
				<el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定
				</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import UserSelect from '@/components/userSelect'
	export default {
		data() {
			return {
				title: '',
				method: '',
				visible: false,
				loading: false,
				inputForm: {
					id: '',
					sysuser: {
						id: ''
					},
					isaccount: '',
					imageID: '',
					oldUrl: '',
					dmzUrl: '',
					type: '',
					invoiceCode: '',
					invoiceNo: '',
					invoiceDate: '',
					noTaxAmount: '',
					checkCode: '',
					withTaxAmount: '',
					amount: '',
					payerTaxNo: '',
					payerName: '',
					sellerTaxNo: '',
					sellerName: '',
					buyerAddTel: '',
					buyerBankNo: '',
					sellerAddTel: '',
					sellerBankNo: '',
					remarks: ''
				}
			}
		},
		components: {
			UserSelect
		},
		methods: {
			init(method, id) {
				this.method = method
				this.inputForm.id = id
				if (method === 'add') {
					this.title = `新建个人发票夹`
				} else if (method === 'edit') {
					this.title = '修改个人发票夹'
				} else if (method === 'view') {
					this.title = '查看个人发票夹'
				}
				this.visible = true
				this.loading = false
				this.$nextTick(() => {
					this.$refs.inputForm.resetFields()
					if (method === 'edit' || method === 'view') { // 修改或者查看
						this.loading = true
						this.$http({
							url: `/zhaohang/invoice/web/userticket/sysUserTicket/queryById?id=${this.inputForm.id}`,
							method: 'get'
						}).then(({
							data
						}) => {
							this.inputForm = this.recover(this.inputForm, data.sysUserTicket)
							this.loading = false
						})
					}
				})
			},
			// 表单提交
			doSubmit() {
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						this.loading = true
						this.$http({
							url: `/zhaohang/invoice/web/userticket/sysUserTicket/save`,
							method: 'post',
							data: this.inputForm
						}).then(({
							data
						}) => {
							this.loading = false
							if (data && data.success) {
								this.visible = false
								this.$message.success(data.msg)
								this.$emit('refreshDataList')
							}
						})
					}
				})
			}
		}
	}
</script>
